package com.sq.partner.manager.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.sq.partner.manager.dao.ICoreDeptDao;
import com.sq.partner.manager.dao.IGatewayChannelInfoConfigDao;
import com.sq.partner.manager.dao.IGatewayCreditPolicyDao;
import com.sq.partner.manager.mybatis.model.CoreDept;
import com.sq.partner.manager.mybatis.model.GatewayChannelInfo;
import com.sq.partner.manager.service.IGatewayCreditPolicyListService;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.excel.ExcelEntity;
import com.sq.partner.manager.util.excel.ExportExcelBuilderTool;
@Service
public class GatewayCreditPolicyListServiceImpl implements IGatewayCreditPolicyListService {
	
	@Resource
	ExportExcelBuilderTool exportExcelBuilderTool;
	
	@Resource
	private ICoreDeptDao coreDeptDao;
	
	@Resource
	private IGatewayChannelInfoConfigDao channelInfoConfigDao;
	
	@Resource
	private IGatewayCreditPolicyDao gatewayCreditPolicyDao;

	
	/**
	 * 查询当前用户的权限机构
	 */
	@Override
	public List<CoreDept> queryPrivilegeBranch(String deptCodeStr)
			throws Exception {
		return coreDeptDao.queryDeptList(deptCodeStr);
	}

	/**
	 * 查询当前用户的权限机构的合作伙伴
	 */
	@Override
	public Page<GatewayChannelInfo> queryChannelInfoPageOfLife(
			Page<GatewayChannelInfo> page) throws Exception {
		return channelInfoConfigDao.queryChannelInfoPageOfLife(page);
	}
	/**
	 * 条件分页查询信保保单
	 */
	@Override
	public Page<Map<String, Object>> queryCreditPolicyPageByCriteria(Page page) throws Exception {
		
		return gatewayCreditPolicyDao.queryCreditPolicyPageByCriteria(page);
	}

	/**
	 * 导出借意险投保信息查询
	 */
	@Override
	public List<Map<String, Object>> queryCreditPolicyListByCriteria(
			Map<String, Object> map) throws Exception {
		return gatewayCreditPolicyDao.queryCreditPolicyListByCriteria(map);
	}
	
	/**
	 * 导出借意险投保信息
	 */
	@Override
	public void downloadCreditPolicyFile(List<Map<String, Object>> creditPolicyList,HttpServletResponse response) throws Exception{
		ExcelEntity excel = new ExcelEntity();
		excel.setResults(creditPolicyList);
		excel.setFileName("CreditPolicyInfo");
		excel.setTitles("借款人姓名(投、被保人姓名),借款人身份证号码（投、被保人证件号码）,借款人本金金额（不含利息）（保险金额）,融资需求起息日(保险起期),融资需求到期日(保险止期),贷款类型");
		excel.setTitleKeys("REAL_NAME,CERTI_CODE,BORROW_AMOUNT,BEGIN_DATE,END_DATE,BUS_TYPE");
		excel.setColumns("35,50,50,33,33,11");
		exportExcelBuilderTool.buildExcel(response,excel);
	}
	
}
